package com.aeoj.clientmanagement.exception;

import com.aeoj.clientmanagement.domain.response.R;
import com.aeoj.clientmanagement.enums.ResponseCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public R businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return R.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R runtimeExceptionHandler(Exception e) {
        log.error("Exception", e);
        return R.error(ResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode(), ResponseCodeEnum.INTERNAL_SERVER_ERROR.getMessage());
    }
}
